<include file="public:header"/>
<script charset="utf-8" src="__STATIC__/js/jquery.js" type="text/javascript"></script>
<script>
    $(function () {

        $('#free').change(function () {
            if ($(this).val() == 2) {
                $('#address_form').show();
            } else {
                $('#address_form').hide();
            }
        });
        set_address();
    })

    function set_address() {
        var addr_id = $("#free").find("option:selected").val();

        if (addr_id == 2) {

            $('#address_form').show();
        }
        else {
            $('#address_form').hide();

        }
    }
</script>
<!--编辑商品-->
<div class="subnav">
    <h1 class="title_2 line_x">编辑商品</h1>
</div>
<form id="info_form" action="{:u('item/edit')}" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$info.id}">

    <div class="pad_lr_10">
        <div class="col_tab">
            <ul class="J_tabs tab_but cu_li">
                <li class="current">基本信息</li>
            </ul>
            <div class="J_panes">
                <div class="content_list pad_10">
                    <table width="100%" cellpadding="2" cellspacing="1" class="table_form">
                        <tr>
                            <th width="120">所属分类 :</th>
                            <td>
                                <select class="J_cate_select mr10" data-pid="0"
                                        data-uri="{:U('item_cate/ajax_getchilds', array('type'=>0))}"
                                        data-selected="{$selected_ids}">
                                </select>
                                <input type="hidden" name="cate_id" id="J_cate_id" value=""/>
                                <input type="hidden" name="cid" id="J_cid" value="{$info.cid}"/>
                            </td>
                        </tr>
                        <tr>
                            <th>排序 :</th>
                            <td><input type="text" name="orderby" id="J_orderby" class="input-text" size="6"
                                       value="{$info.orderby}"></td>
                        </tr>
                        <tr>
                            <th>商品名称 :</th>
                            <td><input type="text" name="title" id="J_title" class="input-text" size="60"
                                       value="{$info.title}"></td>
                        </tr>
                        <tr>
                            <th>副标题 :</th>
                            <td><input type="text" name="fbt" id="J_fbt" class="input-text" size="60"
                                       value="{$info.fbt}"></td>
                        </tr>
                        <volist name="selects" id="sel">
                            <tr>
                                <th>{$sel} :</th>
                                <td>
                                    <select name="{$key}" id="{$key}" class="input-text">
                                        <option value="99" <?php if($info[$key] == 99) echo 'selected'; ?> >高</option>
                                        <option value="40" <?php if($info[$key] == 40) echo 'selected'; ?> >中</option>
                                        <option value="1" <?php if($info[$key] == 1) echo 'selected'; ?> >低</option>
                                    </select>
                                </td>
                            </tr>
                        </volist>
                        <tr>
                            <th>厚度 :</th>
                            <td><input type="text" name="houdu" id="J_houdu" class="input-text" size="6"
                                       value="{$info.houdu}"></td>
                        </tr>
                        <tr>
                            <th>耐刮 :</th>
                            <td><input type="text" name="naigua" id="J_naigua" class="input-text" size="6"
                                       value="{$info.naigua}"></td>
                        </tr>
                        <tr>
                            <th>隔热率 :</th>
                            <td><input type="text" name="geredu" id="J_geredu" class="input-text" size="6"
                                       value="{$info.geredu}"></td>
                        </tr>
                        <tr>
                            <th>透光率 :</th>
                            <td><input type="text" name="touguangdu" id="J_touguangdu" class="input-text" size="6"
                                       value="{$info.touguangdu}"></td>
                        </tr>

                        <tr>
                            <th>防晒指数 :</th>
                            <td><input type="text" name="fangshai" id="J_fangshai" class="input-text" size="6"
                                       value="{$info.fangshai}"></td>
                        </tr>
                        <tr>
                            <th>适用范围 :</th>
                            <td><input type="text" name="syfw" id="J_syfw" class="input-text" size="60"
                                       value="{$info.syfw}"></td>
                        </tr>
                        <tr>
                            <th>雾度 :</th>
                            <td>
                                <input type="text" name="wudu" id="J_wudu" class="input-text" size="10"
                                       value="{$info[wudu]}">
                            </td>
                        </tr>

                        <tr>
                            <th>描述 :</th>
                            <td><textarea name="description" cols="80" rows="2">{$info.description}</textarea></td>
                        </tr>
                        <tr>
                            <th>商品图片 :</th>
                            <td>
                                <div>
                                    <img src="{$info.img}" id="img-preview" class="preview">
                                </div>
                                <input id="pic" type="file" name="img" data-show="#img-preview"/>
                            </td>
                        </tr>

                        <tr>
                            <th>商品价格 :</th>
                            <td><input id='J_price' onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9.]/g,'')" type="text"
                                       name="price" class="input-text" size="10" value="{$info.price}"> 元
                            </td>
                        </tr>
                      <!--   <tr>
                            <th>最高奖励 :</th>
                            <td><input id='J_jianglimax' onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')"
                                       onafterpaste="this.value=this.value.replace(/[^0-9.]/g,'')" type="text"
                                       name="jianglimax" class="input-text" size="10" value="{$info.jianglimax}"> 元
                            </td>
                        </tr> -->
                        <tr>
                            <th>商品库存 :</th>
                            <td><input id='J_goods_stock' onkeyup="this.value=this.value.replace(/\D/g,'')"
                                       onafterpaste="this.value=this.value.replace(/\D/g,'')" type="text"
                                       name="goods_stock" class="input-text" size="10" value="{$info.num}"></td>
                        </tr>
                        <tr>
                            <th>属性:</th>
                            <td><input type="checkbox" name="news"
                                <if condition="$info.new eq 1">checked</if>
                                >新品&nbsp;
                                <input type="checkbox" name="tuijian"
                                <if condition="$info.hot eq 1">checked</if>
                                >推荐
                            </td>
                        </tr>
                        <tr>
                            <th>性能 :</th>
                            <td><textarea name="xingneng" id="info"
                                          style="width:68%;height:400px;visibility:hidden;resize:none;">{$info.xingneng}</textarea>
                            </td>
                        </tr>
                    </table>
                </div>

            </div>
            <div class="mt10"><input type="submit" value="{:L('submit')}" class="btn btn_submit"></div>
        </div>
    </div>
    <input type="hidden" name="menuid" value="{$menuid}"/>
</form>

<include file="public:footer"/>
<script type="text/javascript">
    $('.J_cate_select').cate_select('请选择');
    $(function () {
        $.getJSON('static/data/config.json', function(cfg) {
            //自动计算最高奖励
            var Cate1 = $('#Cate1');
            var maxReword = $('#J_jianglimax');
            $('#J_price').change(function() {
                var prize = this.value;
                var cate1 = Cate1.val() - 1;
                if(cate1 > -1 && cate1 < cfg.reword.length) {
                    var max = prize * cfg.reword[cate1];
                    maxReword.val(Math.round(max));
                }
            });
        });

        $('#pic').change(function () {
            var v = $(this).val();
            var target = $(this).data('show');
            var reader = new FileReader();
            reader.onload = function (e) {
                $(target).attr('src', e.target.result);
            };
            reader.readAsDataURL(this.files[0]);
        });

        //自动获取标签
        $('#J_gettags').live('click', function () {
            var title = $.trim($('#J_title').val());
            if (title == '') {
                $.pinphp.tip({content: lang.article_title_isempty, icon: 'alert'});
                return false;
            }
            $.getJSON('{:U("item/ajax_gettags")}', {title: title}, function (result) {
                if (result.status == 1) {
                    $('#J_tags').val(result.data);
                } else {
                    $.pinphp.tip({content: result.msg});
                }
            });
        });
        $.formValidator.initConfig({formid: "info_form", autotip: true});
        $("#J_title").formValidator({onshow: '请填写商品名称', onfocus: '请填写商品名称'}).inputValidator({
            min: 1,
            onerror: '请填写商品名称'
        });
        $("#J_fbt").formValidator({onshow: '请填写副标题', onfocus: '请填写副标题'}).inputValidator({min: 1, onerror: '请填写副标题'});
        $("#J_price").formValidator({onshow: '请填写商品价格', onfocus: '请填写商品价格'}).inputValidator({
            min: 1,
            onerror: '请填写商品价格'
        });
        $("#J_goods_stock").formValidator({onshow: '请填写商品库存', onfocus: '请填写商品库存'}).inputValidator({
            min: 1,
            onerror: '请填写商品库存'
        });
        $("#J_syfw").formValidator({onshow: '请填写适用范围', onfocus: '请填写适用范围'}).inputValidator({
            min: 1,
            onerror: '请填写适用范围'
        });
        $("#J_naigua").formValidator({onshow: '请填写耐刮', onfocus: '请填写耐刮'}).inputValidator({min: 1, onerror: '请填写耐刮'});
        $("#J_houdu").formValidator({onshow: '请填写厚度', onfocus: '请填写厚度'}).inputValidator({min: 1, onerror: '请填写厚度'});
        $("#J_wudu").formValidator({onshow: '请填写雾度', onfocus: '请填写雾度'}).inputValidator({min: 1, onerror: '请填写雾度'});

        $("#J_geredu").formValidator({onshow: '请填写隔热度(1-100)', onfocus: '请填写隔热度(1-100)'}).inputValidator({
            min: 1,
            onerror: '请填写隔热度'
        });
        $("#J_touguangdu").formValidator({onshow: '请填写透光度(1-100)', onfocus: '请填写透光度(1-100)'}).inputValidator({
            min: 1,
            onerror: '请填写透光度'
        });
        $("#J_fangshai").formValidator({onshow: '请填写防晒指数(1-100)', onfocus: '请填写防晒指数(1-100)'}).inputValidator({
            min: 1,
            onerror: '请填写防晒指数'
        });

        $("#J_jianglimax").formValidator({onshow: '请填写最高奖励', onfocus: '请填写最高奖励'}).inputValidator({
            min: 1,
            onerror: '请填写最高奖励'
        });
    });

    function add_file() {
        $("#next_upload_file .uplode_file").clone().insertAfter($("#first_upload_file .uplode_file:last"));
    }
    function del_file_box(obj) {
        $(obj).parent().parent().remove();
    }
    function add_attr() {
        $("#hidden_attr .add_item_attr").clone().insertAfter($("#item_attr .add_item_attr:last"));
    }
    function del_attr(obj) {
        $(obj).parent().parent().remove();
    }
</script>

</body>
</html>
<script src="__STATIC__/js/jquery/plugins/colorpicker.js"></script>
<script src="__STATIC__/js/kindeditor/kindeditor.js"></script>
<script>

    $(function () {
        KindEditor.create('#info', {
            uploadJson: '{:U("attachment/editer_upload")}',
            fileManagerJson: '{:U("attachment/editer_manager")}',
            allowFileManager: true
        });
        $('ul.J_tabs').tabs('div.J_panes > div');

        //颜色选择器
        $('.J_color_picker').colorpicker();

        //自动获取标签
        $('#J_gettags').live('click', function () {
            var title = $.trim($('#J_title').val());
            if (title == '') {
                $.pinphp.tip({content: lang.article_title_isempty, icon: 'alert'});
                return false;
            }
            $.getJSON('{:U("article/ajax_gettags")}', {title: title}, function (result) {
                if (result.status == 1) {
                    $('#J_tags').val(result.data);
                } else {
                    $.pinphp.tip({content: result.msg});
                }
            });
        });

    });
</script>